package com.utils;

import java.util.List;

import com.Card;
import com.Hand;
import com.Suit;

public class Regulations {

	public static Card retrieveWinnerCard(Card card1, Card card2, Card card3,
			Card card4) {
		Card winner = card1;

		winner = retrieveWinnerCard(winner, card2);
		winner = retrieveWinnerCard(winner, card3);
		winner = retrieveWinnerCard(winner, card4);

		return winner;
	}

	private static Card retrieveWinnerCard(Card card1, Card card2) {

		boolean isSameSuit = false;

		if ((card1.getSuit() == Hand.getTrump() && card2.getSuit() == Hand
				.getTrump())
				|| (card2.getSuit() == Hand.getHandCard())) {
			isSameSuit = true;
		}

		if (isSameSuit) {
			if (card1.getRank() > card2.getRank()) {
				return card1;
			} else {
				return card2;
			}
		} else {
			if (card1.getSuit() == Hand.getTrump()) {
				return card1;
			} else if (card2.getSuit() == Hand.getTrump()) {
				return card2;
			} else {
				return card1;
			}
		}

	}

	public static boolean isCardValid(Card card, Suit handSuit, List<Card> cards) {
		if (card.getSuit().equals(handSuit)) {
			return true;
		} else {
			for (Card c : cards) {
				if (c.getSuit().equals(handSuit)) {
					return false;
				}
			}
		}
		return true;
	}
}
